package com.example.demo.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisTestRunner implements CommandLineRunner {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void run(String... args) throws Exception {
        try {
            stringRedisTemplate.opsForValue().get("");
            System.out.println("请求redis正常");
        } catch (Exception e) {
            System.out.println("请求redis异常，" +  e.getMessage());
            e.printStackTrace();
        }
    }
}
